#!/bin/sh

APP_PATH=`cd "$(dirname "$0")"; cd ..; pwd`
echo $APP_PATH
PYTHON_PATH=/usr/bin/python

cd ${APP_PATH}/src

start (){
    echo "Starting~~~~~~~~~~~~"
    /usr/bin/uwsgi --ini ${APP_PATH}/etc/diver.ini --socket /tmp/diver.sock
}
stop (){
    echo "Stoping~~~~~~~~~~~~"
    PID=`ps aux | grep -v grep | grep /tmp/diver.sock | awk '{print $2}'`
    for i in $PID; do
	echo $i
	`kill -9 $i`
    done
}

restart() {
    stop
    sleep 3
    start
}

case "$1" in
  start)
       start
       ;;

  stop)
       stop
       ;;

  restart)
       restart
       ;;

  *)
    echo "Usage: $NAME {start|stop|restart}" >&2
    exit 1
    ;;
esac

cd $DIR
